package com.cn.zy.zheda.demo.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.cn.zy.zheda.demo.constant.ParamConstant;
import com.cn.zy.zheda.demo.constant.UrlConstant;
import com.cn.zy.zheda.demo.controller.response.UserInfoRes;
import com.cn.zy.zheda.demo.service.DeviceService;
import com.cn.zy.zheda.demo.utils.HttpUtil;
import org.springframework.stereotype.Service;

/**
 * @author zhangyi
 * @date 2018/12/19 14:44
 */
@Service
public class DeviceServiceImpl implements DeviceService{


    /**
     * 获取设备id
     *
     * @param customerId
     * @return
     */
    @Override
    public String getDeviceId(String customerId,String token) {
        String deviceUrl = UrlConstant.DEVICE_URL;
        String userInfo = HttpUtil.sendGet(UrlConstant.USER_INFO_URL, token);
        System.out.println("0000000000000000000000000000000000");
        System.out.println(userInfo);
        System.out.println("0000000000000000000000000000000000");
        UserInfoRes userInfoRes =
                JSON.parseObject(userInfo, new TypeReference<UserInfoRes>() {});
//        获取customerId
        String id = userInfoRes.getCustomerId().getId();
        String deviceInfo = HttpUtil.sendGet(deviceUrl.replace(ParamConstant.ALARM_1,id), token);
        System.out.println("==============================");
        System.out.println(deviceInfo);
        return null;
    }
}
